<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title site-title">
		<legend>
			<a name="fixbar" style="font-size: 16px; color: #ce2424;">学生管理</a>
		</legend>
	</fieldset>
	<form class="layui-form" id="myForm" method="post" lay-filter="stuform">
		<div class="layui-form-item">
			<div class="layui-inline" style="width: 350px;">
				<label class="layui-form-label">班级名称：</label>
				<div class="layui-input-block">
					<select id="bjid" lay-filter="bjselect" lay-verify="required"
						lay-search>
						<c:forEach var="d" items="${bjs}">
							<option value="${d.id}">${d.name}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="layui-inline" style="width: 350px;">
				<label class="layui-form-label">学员姓名：</label>
				<div class="layui-input-block">
					<select id="student" lay-filter="stuselect" lay-search>
						<option value=""></option>
						<c:forEach var="s" items="${stu}">
							<option value="${s.id}">${s.name}</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<c:if test="${ishas}">
				<div class="layui-inline" style="width: 350px;">
					<label class="layui-form-label">是否毕业：</label>
					<div class="layui-input-block">
						<input type="checkbox" lay-filter="status" lay-skin="switch"
							lay-text="是|否">
					</div>
				</div>
			</c:if>
		</div>
	</form>
	<table id="student_table"></table>
	<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="add_panel">新增</button>
  	</div>
</script>

	<script type="text/javascript">
	
	layui.use('form', function(){
		var form = layui.form;
		form.render();
	})

		layui.use('form', function() {
			var form = layui.form;
			form.render('select');

			form.on('select(stuselect)', function(data) {
				var suuid = data.value;
				var bjuuid = $("#bjid").val();
				layui.use('table', function() {
					var table = layui.table;
					table.reload('stu', {
						url : 'student/page',
						where : {
							bjuuid : bjuuid,
							suuid : suuid
						},
						page : {
							curr : 1
						//重新从第 1 页开始
						}
					});
				});
			});

			form.on('select(bjselect)', function(data) {
				var bjuuid = data.value;
				$("#student").empty();
				var id = $(this).attr("lay-value");
				$.ajax({
					type : "POST",
					data : {
						id : id
					},
					url : "student/select",
					success : function(data) {
						var form = layui.form;
						var json = data;
						$("#student").append('<option value=""></option>');
						for (var i = 0; i < data.length; i++) {
							var json = data[i];
							var str = "";
							str += '<option value="'+json.id+'">' + json.name
									+ '</option>';
							$("#student").append(str);
						}
							form.render('select');
					}
				});
				layui.use('table', function() {
					var table = layui.table;
					table.reload('stu', {
						url : 'student/page',
						where : {
							bjuuid : bjuuid,
							suuid : ""
						},
						page : {
							curr : 1
						//重新从第 1 页开始
						}
					});
				});
			});
			
			
			form.on('switch(status)', function(obj) {
				var isstart = obj.elem.checked;	
				$("#bjid").empty();
				$.ajax({
					type : "POST",
					url : "student/banjiselect",
					data:{isstart:isstart},
					success : function(data) {
						var form = layui.form;
						var json = data;
						for (var i = 0; i < data.length; i++) {
							var json = data[i];
							var str = "";
							str += '<option value="'+json.id+'">' + json.name
									+ '</option>';
							$("#bjid").append(str);
						}
							form.render('select');
							layui.use('table', function() {
								var table = layui.table;
								var bj = data[0].id;
								table.reload('stu', {
									url : 'student/page',
									where : {
										bjuuid : bj,
										suuid : ""
									},
									page : {
										curr : 1
									//重新从第 1 页开始
									}
								});
							});
					}
				});
				
			});
		});
        var bjid = $("#bjid").val();
		var option = {
			elem : '#student_table',
			title : '学生列表',
			path : 'student',
			height : 'full-265',
			id : 'stu',
			addurl : 'edit',
			where : {
				username : '${param.username}',
				name : '${param.name}',
				sex : '${param.sex}',
				address : '${param.address}',
				phone : '${param.phone}',
				workUnit : '${param.workUnit}',
				bjuuid : bjid
			},
			//sort: 'name',
			//winWidth: '800px',
			toolbar : '#toolbarDemo',
			cols : [ [ {
				field : 'tbClass',
				title : '班级',
				templet : function(d) {
					return d.tbClass ? d.tbClass.name : '';
				}
			}, {
				field : 'name',
				title : '姓名'
			}, {
				field : 'username',
				title : '用户名'
			}, {
				field : 'sex',
				title : '性别'
			}, {
				field : 'idcode',
				hide : true,
				title : '身份证号'
			}, {
				field : 'nation',
				hide : true,
				title : '民族'
			}, {
				field : 'politics',
				hide : true,
				title : '政治面貌'
			}, {
				field : 'degree',
				hide : true,
				title : '文化程度'
			}, {
				field : 'bron',
				hide : true,
				title : '出生日期'
			}, {
				field : 'email',
				hide : true,
				title : '邮箱'
			}, {
				field : 'officetel',
				hide : true,
				title : '办公电话'
			}, {
				field : 'job',
				hide : true,
				title : '现任职务'
			}, {
				field : 'jobLevel',
				hide : true,
				title : '职级'
			}, {
				field : 'postalCode',
				hide : true,
				title : '邮政编码'
			}, {
				field : 'speciality',
				hide : true,
				title : '专业技术职称'
			}, {
				field : 'address',
				hide : true,
				title : '单位地址'
			}, {
				field : 'phone',
				title : '手机'
			}, {
				field : 'workUnit',
				hide : true,
				title : '工作单位'
			}, {
				field : 'groupNumber',
				hide : true,
				title : '组号'
			}, {
				field : 'siteNumber',
				hide : true,
				title : '座位号'
			}, {
				field : 'carnumber',
				hide : true,
				title : '车牌号'
			}, {
				fixed : 'right',
				title : '操作',
				toolbar : '#barDemo2',
				width : 200
			} ] ]
		}
		var currRow = '${param.currRow==null?null:param.currRow}';
		var limit = ${param.limit == null ? 'null' : param.limit};
		var page = ${param.page == null ? 'null' : param.page};
		var classTable = new LayUiTable(option, currRow, limit, page);
		classTable.init();

		function search() {
			classTable.search();
		}

		function empty() {
			classTable.empty();
		}
	</script>
</body>
</html>